package com.ymatou.iapi.csim.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.csim.parameter.SaveOrUpdateDiscourseBean;
import com.ymatou.iapi.csim.service.SaveOrUpdateDiscourseCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CsimCallService;
import com.ymttest.database.model.ymt_discourse;
import com.ymttest.database.model.ymt_discoursecategory;
import com.ymttest.database.sqlwapper.CSIM.ymt_discourseWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_discoursecategoryWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_individualdiscoursecatetoryWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
/**
*新增或更新话术分类
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SaveOrUpdateDiscourse{
	private static SaveOrUpdateDiscourseBean saveorupdatediscourseBean;
	private static SaveOrUpdateDiscourseCall saveorupdatediscourseCall;
	private Integer csId=Integer.parseInt(EnvSetup.getData("csId").toString());
	private static ymt_discourseWapper discourseWapperWapper=new ymt_discourseWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("新增或更新话术分类");
	}

	@Before
	public void caseUp() {
		saveorupdatediscourseBean=new SaveOrUpdateDiscourseBean();
		saveorupdatediscourseCall=new SaveOrUpdateDiscourseCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(saveorupdatediscourseCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SaveOrUpdateDiscourse_1() {
		Logger.start(true,"新增或更新话术-验证不存在,新增");
		try {
			saveorupdatediscourseBean.setId(TestDataManager.getRandomUUID().toString());
			saveorupdatediscourseBean.setCategoryId(TestDataManager.getRandomUUID().toString());
			saveorupdatediscourseBean.setTitle("自动化测试_"+TestDataManager.getRandomNum(5));
			saveorupdatediscourseBean.setCsId(csId);
			saveorupdatediscourseBean.setSort(1);
			saveorupdatediscourseBean.setRoleType("MAIJIA_KEFU");
			saveorupdatediscourseCall.setData(saveorupdatediscourseBean);
			saveorupdatediscourseCall.callService();			
			//验证
			Logger.verifyEquals("0", saveorupdatediscourseCall.getResult().get("ErrorCode").toString(), "验证errorCode");
			Logger.verifyEquals(true, saveorupdatediscourseCall.getResult().get("Success"), "验证Success");
			Logger.verifyEquals("200", saveorupdatediscourseCall.getStatus(), "验证Status");
			ymt_discourse dis=discourseWapperWapper.selectByPrimaryKey(saveorupdatediscourseBean.getId());
			Logger.verifyEquals(saveorupdatediscourseBean.getCsId(), dis.getCsId(), "验证CSId");
			Logger.verifyEquals(saveorupdatediscourseBean.getTitle(), dis.getTitle(), "验证Title");
			Logger.verifyEquals(saveorupdatediscourseBean.getSort(), dis.getSort(), "验证Sort");
			Logger.verifyEquals(saveorupdatediscourseBean.getRoleType(), dis.getRoleType(), "验证RoleType");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SaveOrUpdateDiscourse_2() {
		Logger.start(true,"新增或更新话术-验证存在,更新");
		try {
			saveorupdatediscourseBean.setId(TestDataManager.getRandomUUID().toString());
			saveorupdatediscourseBean.setCategoryId(TestDataManager.getRandomUUID().toString());
			saveorupdatediscourseBean.setTitle("自动化测试_"+TestDataManager.getRandomNum(5));
			saveorupdatediscourseBean.setCsId(csId);
			saveorupdatediscourseBean.setSort(1);
			saveorupdatediscourseBean.setRoleType("MAIJIA_KEFU");
			saveorupdatediscourseCall.setData(saveorupdatediscourseBean);
			saveorupdatediscourseCall.callService();
			//更新
			saveorupdatediscourseBean.setTitle("自动化测试_"+TestDataManager.getRandomNum(5));
			saveorupdatediscourseCall.setData(saveorupdatediscourseBean);
			saveorupdatediscourseCall.callService();		
			//验证
			Logger.verifyEquals("0", saveorupdatediscourseCall.getResult().get("ErrorCode").toString(), "验证errorCode");
			Logger.verifyEquals(true, saveorupdatediscourseCall.getResult().get("Success"), "验证Success");
			Logger.verifyEquals("200", saveorupdatediscourseCall.getStatus(), "验证Status");
			ymt_discourse dis=discourseWapperWapper.selectByPrimaryKey(saveorupdatediscourseBean.getId());
			Logger.verifyEquals(saveorupdatediscourseBean.getCsId(), dis.getCsId(), "验证CSId");
			Logger.verifyEquals(saveorupdatediscourseBean.getTitle(), dis.getTitle(), "验证Title");
			Logger.verifyEquals(saveorupdatediscourseBean.getSort(), dis.getSort(), "验证Sort");
			Logger.verifyEquals(saveorupdatediscourseBean.getRoleType(), dis.getRoleType(), "验证RoleType");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}